#ifndef __MERCKU_MTKMESH_DEFINE_H__
#define __MERCKU_MTKMESH_DEFINE_H__

#include <core/all.h>
#include <mapd_interface_ctrl.h> // mapd

#define DFT_MAPD_SOCKET "/tmp/mapd_ctrl"
#define DAT_FILE_MAP_USER "/etc/map/mapd_user.cfg"

typedef enum
{
    MAPD_EVENT_PING = 0,
    MAPD_EVENT_NO_EVENT = MAPD_EVENT_PING,  // ping 不处理，认为是没有收到事件
    WIRELESS_CLIENT_JOIN_NOTIF = 1,
    WIRELESS_CLIENT_LEAVE_NOTIF = 2,
    ETHERNET_CLIENT_JOIN_NOTIF = 3,
    ETHERNET_CLIENT_LEAVE_NOTIF = 4,
    CH_PREF_NOTIF = 5,
    HIGHER_LAYER_PAYLOAD = 6,
    ONBOARDING_STATUS_NOTIF = 7,
    TRIGGER_MAP_STEERING_NOTIF = 8,
    GET_BEACON_REPORT_NOTIF = 9,
    GET_BTM_RESPONSE_NOTIF = 10,
    SEC_CONNECTION_FAILURE = 11,
    USER_FAIL_EVENTS = 12,
} MapdEventType;
#define ETH_ALEN 6
#define MAX_SSID_LEN 32

struct mapd_user_event
{
    int event_id;
    char event_body[0];
};

struct mapd_user_higher_layer_data_event
{
    unsigned int buf_len;
    unsigned char buf[4096];
};

struct mapd_user_iface_wireless_client_event
{
    unsigned char sta_mac[ETH_ALEN];
    unsigned char bssid[ETH_ALEN];
    char ssid[MAX_SSID_LEN + 1];
};

struct mapd_user_iface_eth_client_event
{
    unsigned char sta_mac[ETH_ALEN];
    unsigned char almac[ETH_ALEN];
};

typedef char ALMac[ETH_ALEN];
// #define ALMac char[ETH_ALEN]

typedef struct {
    MapdEventType type;
    ALMac client_mac;
    union {
        char higher_layer_payload[1024];
    } data;
} MapdEvent;

/**
 * @brief 打开 mapd 接口。
 * 
 * @param socket mapd 的 socket 文件路径。如果为 NULL，则使用默认路径。
 * @return struct mapd_interface_ctrl* mapd 接口。未打开，则返回空。
*/
struct mapd_interface_ctrl *open_mapd_interface();
void close_mapd_interface(struct mapd_interface_ctrl *inst);
MError *mapd_read_event(struct mapd_interface_ctrl *inst, MapdEvent *event, uint64_t timeout_ms);


/**
 * @brief 通过 mapd 发送消息给指定的 almac。
*/
MError *mapd_send_msg(const char *dst_almac, const char *payload);

typedef enum {
    DRNotSet = 0,
    DRController = 1,
    DRAgent = 2,
} DeviceRole;




#endif // __MERCKU_MTKMESH_DEFINE_H__